<?php
class InterviewModel extends Model
{
	private $interviewAnswers;
	
	public function setInterviewAnswers($interviewAnswers){
		$this->interviewAnswers = $interviewAnswers;   //赋值答案表模型
	}
	
	/**
	 * @author yinyi
	 * @description 获取问题的所有答案
	 * @date 2010-06-11
	 */
	public function getInterviewAnswers($kind,$type,$count,$uid){
		//初始化问题及问题答案
		$interviews = $interviewAnswers = array();
		
		//获取问题及问题答案数据
		$interviews = $this->query("select * from ts_interview where kind =".$kind." and type =".$type." and id not in (select pid from ts_interview_record where uid =".$uid.") order by id limit 0,".$count);
		$interviewAnswerList = $this->interviewAnswers->findAll();
		
		//根据问题重组答案
		foreach ($interviews as &$interview){
			foreach ($interviewAnswerList as $interviewAnswer){
				if($interview['id']==$interviewAnswer['pid']){
					$interview['interviewAnswerList'][]=$interviewAnswer;
				}
			}
		}
		return $interviews;
	}	
	
	/**
	 * @author yinyi
	 * @description 获取给定Id集合的问题及答案
	 * @date 2010-06-11
	 */
	function getInterviewByIds($pids){
		$interviews = $this->query("select * from ts_interview where id in(".$pids.")");
		foreach ($interviews as &$interview){
			$interviewAnswerList = $this->interviewAnswers->where("pid = ".$interview['id'])->select();
			foreach($interviewAnswerList as &$interviewAnswer){
				$interview['interviewAnswerList'][] = $interviewAnswer;
			}
		}
		return $interviews;
	}
}
?>